<?php

namespace addons\kuerp\model;

use think\Model;
class ExpenseInfo extends Model
{

    // 表名
    protected $name = 'kuerp_expense_info';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';

    protected $append = [
        'expense_time_text'
    ];

    protected function getExpenseTimeTextAttr($value, $data) {
        $value = $value ? $value : (isset($data['expense_time']) ? $data['expense_time'] : '');
        return is_numeric($value) ? date("Y-m-d", $value) : $value;
    }

    protected function setExpenseTimeAttr($value)
    {
        return $value === '' ? 0 : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    public function getInfo($id)
    {
        $list = $this->where(['expense_id' => $id])->select();
        return $list ? collection($list)->toArray() : [];
    }
}
